/*
 * Copyright (c) 2009-2013 EvTech Project
 * All rights reserved.
 * 
 * This file is part of Symbol Matching.
 *
 * Symbol Matching is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 *
 * Symbol Matching is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Symbol Matching.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package fi.honkalampisaatio.reaktiopeli.game;

import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;


public class MeterPanel extends JPanel {

	private static final long serialVersionUID = 4602470648808555584L;
	private long totalTime = 0;
	private long leftTime = 0;

	public void paintComponent(Graphics g) {
        super.paintComponent(g);       
        Graphics2D g2 = (Graphics2D) g;
		//setBounds((int)(getParent().getWidth()*0.2), 50, (int)(getParent().getWidth()*0.6), 50);
        int w = this.getWidth()-1;
        int h = this.getHeight()-1;
        int leftW = totalTime>0 ? (int)(w*leftTime/totalTime) : w;
        g2.drawRect(0, 0, w, h);
        g2.fillRect(0, 0, leftW, h);
	}
	
	public void setTime(long leftTime, long totalTime) {
		this.leftTime = leftTime;
		this.totalTime = totalTime;
		this.repaint();
	}

}
